package com.android.uu.view.HorizontalSlideListView;

import com.android.uu.view.HorizontalSlideListView.UUHorizontalSlideExpandableAdapter;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.HorizontalScrollView;

/**可以侧滑删除的可展开listview
 * 
 * @author GuiyouZhang
 * Date：2016年1月11日 下午7:25:20
 * Email:guiyouzhang@163.com
 */
public class UUHorizontalSlideExpandableListView extends ExpandableListView {

	private UUHorizontalSlideExpandableAdapter mAdapter;
	
	public UUHorizontalSlideExpandableListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if (mAdapter.mLockOnTouch) {
			if (ev.getAction() == MotionEvent.ACTION_MOVE) {
				if (mAdapter.mScrollView != null) {// 而且有滑出的item
					// 那么先将item复位,并将此次事件拦截消费掉
					mAdapter.scrollView(mAdapter.mScrollView,
							HorizontalScrollView.FOCUS_LEFT);
					mAdapter.mScrollView = null;
					return true;
				}
			}
			if (ev.getAction() == MotionEvent.ACTION_UP) {
				mAdapter.mLockOnTouch = false;
			}
		}
		return super.onTouchEvent(ev);
	}

	@Override
	public void setAdapter(ExpandableListAdapter adapter) {
		super.setAdapter(adapter);
		mAdapter = (UUHorizontalSlideExpandableAdapter) adapter;
	}

	
}
